﻿using System;

namespace 电磁检测系统
{
    public class DataProcess
    {

        /// <summary>
        /// 将两个字节拼接成u16数据
        /// </summary>
        /// <param name="byteArray">含有两个字节的数组，高位在前，低位在后</param>
        /// <returns></returns>
        public static UInt16 ByteToU16(byte byte1, byte byte2)
        {
            UInt16 u16 = 0;
            UInt32 u32 = 0;
            //第一种方法：使用BitConverter来转换
            //byte[] byteArray = new byte[] { byte1, byte2 };
            //u16 = BitConverter.ToUInt16(byteArray, 0);
            //第二种方法：移位操作
            //u16 = ((((ushort)byte1) << 8) | (((ushort)(byte2)) & 0xff));
            u32 = (((UInt32)(byte1) << 8) | (((UInt32)(byte2)) & 0xff));
            u16 = Convert.ToUInt16(u32);
            return u16;
        }

    }
}
